#include "Hole.h"
#include "ShootEmUp.h"
#include "GameManager.h"

using namespace Ogre;
using namespace std;



Hole::Hole()
{
	type = HOLE;
	initialize();
}

void Hole::initialize()
{
	mDirection = Vector3::ZERO;

	mEntity = mSceneMgr->createEntity(getName(), "trou.mesh");
	mEntity->setUserObject( this );
	

	mSceneNode = mSceneMgr->getSceneNode(Enemy::DEFAULT_NODE_NAME)->createChildSceneNode(Enemy::DEFAULT_NODE_NAME+string("_")+getName());
	Vector3 initialPosition( 
		Math::RangeRandom(ShootEmUp::WORLD_MIN.x, ShootEmUp::WORLD_MAX.x), 
		Math::RangeRandom(ShootEmUp::WORLD_MIN.y, ShootEmUp::WORLD_MAX.y), 
		ShootEmUp::WORLD_MAX.z
		);
	mSceneNode->setPosition( initialPosition );
	mSceneNode->scale(1.0, 0.1, 1.0);
	if ( mEntity->isAttached() )
		mEntity->getParentSceneNode()->detachObject( mEntity );
	mSceneNode->attachObject( mEntity );
}

bool Hole::frameStarted(const FrameEvent& evt)
{
	move();
	return true;
}

bool Hole::move(void)
{
	if ( mSceneNode->getPosition().z >= (ShootEmUp::WORLD_MIN.z - 100) )
		mSceneNode->translate(Vector3::NEGATIVE_UNIT_Z * moveSpeed);
	else
		GameManager::getSingleton().destroyEnemy( this );
	return true;
}

void Hole::initNbTouch()
{}

void Hole::collisionWithBullet(Bullet* _bullet)
{}

void Hole::collisionWithEnemy(Enemy* _enemy)
{}

